#include "rbTree.h"
#include <ctime>
#include <cstdlib>
#include <iostream>

using std::cout;
using std::endl;

void inOrder(node *p)
{
    if (!p) return;
    inOrder(p->lchild_);
    cout << "data:" << p->data_ << " color:" << p->color_;
    if (p->parent_)
        cout << " parent:" << p->parent_->data_;
    if (p->lchild_)
        cout << " lchild:" << p->lchild_->data_;
    if (p->rchild_)
        cout << " rchild:" << p->rchild_->data_;
    cout << endl;
    inOrder(p->rchild_);
}
int level(node *p)
{
    if (!p) return 0;
    int ll = level(p->lchild_);
    int lr = level(p->rchild_);
    return std::max(ll, lr) + 1;
}

void test()
{
    std::srand(std::time(nullptr));
    rb_tree *tree = new rb_tree();
    for (int i = 0; i < 1000000; ++i)
    {
        tree->insert(rand() % 10000000);
    }
    cout << level(tree->root_) << endl;
    delete tree;
}

void test1()
{
    rb_tree *tree = new rb_tree();
    std::srand(std::time(nullptr));
    int arr[10];
    for (int i = 0; i < 10; ++i)
    {
        int num = std::rand() % 1000;
        tree->insert(num);
        arr[i] = num;
    }
    node *q;
    node *p = tree->search(arr[std::rand()%10], q);
    cout << p->color_ << " " << p->data_ << endl;
    delete tree;
}

int main(int argc, char *argv[])
{
    test1();
}